{
 "metadata": {
  "name": "06-GeomWF"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from pyoptools.all import *"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "L=Edmund.get(\"32494\")\n",
      "C=CCD()\n",
      "\n",
      "S=System(complist=[(L,(0,0,156.),(0,-pi,0)),(C,(0,0,570),(.001,0,0))],n=1.)\n",
      "R=point_source_c(span=(0.06,0.06),wavelength=.65)\n",
      "\n",
      "\n",
      "S.ray_add(R)\n",
      "S.propagate()\n",
      "plot3D(S,center=(0,0,300), size=(600,100),scale=2,rot=[(0,0,-3*pi/8),(0,3*pi/8,0)])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "imshow(C.get_optical_path_map())\n",
      "colorbar()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "poly,error=C.get_optical_path_map_lsq(order=2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print error\n",
      "print poly"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "#Ejercicio:\n",
      "\n",
      "Encontrar la configuraci\u00f3n del motaje \u00f3ptico mostrado, de tal manera que el haz salga colimado"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Creando una funci\u00f3n para calcular par\u00e1metros del sistema"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def opsystem(lp):\n",
      "    L=Edmund.get(\"32494\")\n",
      "    C=CCD()\n",
      "\n",
      "    S=System(complist=[(L,(0,0,lp),(0,-pi,0)),(C,(0,0,570),(0,0,0))],n=1.)\n",
      "    R=point_source_c(span=(0.06,0.06),wavelength=.65)\n",
      "\n",
      "\n",
      "    S.ray_add(R)\n",
      "    S.propagate()\n",
      "    X,Y,Z=C.get_optical_path_data()\n",
      "    return array(Z).std()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "opsystem(158)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Utilizando otras librerias de python para optimizar el sistema"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from scipy.optimize import fmin\n",
      "fmin(opsystem,158)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}